package com.maixy.studyonlineapi.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.maixy.studyonlineapi.entity.ViolationRecord;
import com.maixy.studyonlineapi.mapper.ViolationRecordMapper;
import org.springframework.stereotype.Service;

/**
 * @ClassName ViolationRecordService
 * @Description TODO
 * @Date 2021/3/4 21:56
 * @Author maixy
 */
@Service
public class ViolationRecordService extends BaseMPlusService<ViolationRecord, Long>{
    private final ViolationRecordMapper violationRecordMapper;


    protected ViolationRecordService(ViolationRecordMapper violationRecordMapper) {
        super(ViolationRecord.class, violationRecordMapper);
        this.violationRecordMapper = violationRecordMapper;
    }

    public ViolationRecord findByTypeAndEntityId(Integer type, Long entityId) {
        return violationRecordMapper.selectOne(new QueryWrapper<ViolationRecord>()
                .lambda()
                .eq(ViolationRecord::getType, type)
                .eq(ViolationRecord::getEntityId, entityId)
                .eq(ViolationRecord::getHasDelete, false)
                .orderByDesc(ViolationRecord::getCreateTime)
                .last("limit 1"));
    }
}
